<?php
$dns = 'mysql:host=localhost;dbname=18demo;charset=utf8';
try {
    $pdo = new PDO($dns, 'root', '123456');
    $sql = 'select * from users';
    $result = $pdo->query($sql);
    $result = $result->fetch();
    echo '<pre>';
    print_r($result);
    echo '</pre>';
}catch (PDOException $e) {
    exit($e->getMessage());
}